package de.h_da.fbi.cg.pointcloud.adt;

import de.h_da.fbi.cg.pointcloud.spatial.IPoint;

/**
 * @author Nicolas Gramlich
 * @since 09:55:19 - 11.11.2010
 */
public class Vertex implements IPoint<Float> {
	// ===========================================================
	// Constants
	// ===========================================================

	// ===========================================================
	// Fields
	// ===========================================================

	public final float mX;
	public final float mY;
	public final float mZ;

	public Graph mGraph = null;
	private final int mHashCode;

	// ===========================================================
	// Constructors
	// ===========================================================

	public Vertex(final float pX, final float pY, final float pZ) {
		this.mX = pX;
		this.mY = pY;
		this.mZ = pZ;

		final int prime = 31;
		int result = 1;
		result = prime * result + Float.floatToIntBits(this.mX);
		result = prime * result + Float.floatToIntBits(this.mY);
		result = prime * result + Float.floatToIntBits(this.mZ);
		this.mHashCode = result;
	}

	// ===========================================================
	// Getter & Setter
	// ===========================================================

	public Graph getGraph() {
		return this.mGraph;
	}

	public void setGraph(final Graph pGraph) {
		this.mGraph = pGraph;
	}

	// ===========================================================
	// Methods for/from SuperClass/Interfaces
	// ===========================================================

	@Override
	public String toString() {
		return "[" + this.mX + ", " + this.mY + ", " + this.mZ + "]";
	}

	@Override
	public Float getCoordinate(final int pDimension) {
		switch(pDimension) {
			case 0:
				return this.mX;
			case 1:
				return this.mY;
			case 2:
				return this.mZ;
			default:
				throw new IllegalArgumentException();
		}
	}

	@Override
	public int getDimensions() {
		return 2;
	}

	@Override
	public int hashCode() {
		return this.mHashCode;
	}

	// ===========================================================
	// Methods
	// ===========================================================

	// ===========================================================
	// Inner and Anonymous Classes
	// ===========================================================
}
